package com.sky.mapper;

import com.sky.dto.OrderReportDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.SalesReportDTO;
import com.sky.dto.TurnoverReportDTO;
import com.sky.entity.Orders;
import com.sky.vo.BusinessDataVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrdersMapper {

    /**
     * @description: 新增订单
     * @author: tanbobin
     * @date: 2024/6/6 14:56
     * @param:
     * @param orders
     * @return:
     **/
    void insert(Orders orders);


    /**
     * 根据订单号和用户id查询订单  复制粘贴的代码
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);


    /**
     * 修改订单信息  复制粘贴的代码
     * @param orders
     */
    void update(Orders orders);


    /**
     * @description: 查询指定状态且指定时间之前下单的订单
     * @author: tanbobin
     * @date: 2024/6/7 11:02
     * @param:
     * @param status
     * @param beforeTime
     * @return:
     * @return java.util.List<com.sky.entity.Orders>
     **/
    @Select("select * from orders where status = #{status} and order_time < #{beforeTime}")
    List<Orders> selectByStatusAndLtTime(Integer status, LocalDateTime beforeTime);

    /**
     * @description: 根据订单id获取订单信息
     * @author: tanbobin
     * @date: 2024/6/11 11:44
     * @param:
     * @param id
     * @return:
     * @return com.sky.entity.Orders
     **/
    @Select("select * from orders where id = #{id}")
    Orders getOrderById(Long id);

    /**
     * @description: 订单搜索
     * @author: tanbobin
     * @date: 2024/6/11 17:29
     * @param:
     * @param pageQueryDTO
     * @return:
     * @return java.util.List<com.sky.entity.Orders>
     **/
    List<Orders> list(OrdersPageQueryDTO pageQueryDTO);

    // 根据状态，分别查询出待接单、待派送、派送中的订单数量
    @Select("select count(*) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * @description: 统计指定状态，于指定时间段的应用额数据
     * @author: tanbobin
     * @date: 2024/6/12 10:50
     * @param:
     * @param beginTime
     * @param endTime
     * @param status
     * @return:
     * @return java.util.List<com.sky.dto.TurnoverReportDTO>
     **/
    List<TurnoverReportDTO> selectTurnoverList(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    /**
     * @description: 根据指定时间段，查询指定状态的订单数量
     * @author: tanbobin
     * @date: 2024/6/12 17:25
     * @param:
     * @param beginTime
     * @param endTime
     * @return:
     * @return java.util.List<com.sky.dto.OrderReportDTO>
     **/
    List<OrderReportDTO> countOrderByOrderTimeAndStatus(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    /**
     * @description: 统计指定状态，于指定时间段的菜品销量
     * @author: tanbobin
     * @date: 2024/6/12 19:03
     * @param:
     * @return:
     * @return java.util.List<com.sky.dto.SalesReportDTO>
     **/
    List<SalesReportDTO> orderNameListAndStatus(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    /**
     * @description: 统计指定状态，于指定时间段的运营数据
     * @author: tanbobin
     * @date: 2024/6/13 11:09
     * @param:
     * @param beginTime
     * @param endTime
     * @return:
     * @return com.sky.vo.BusinessDataVO
     **/
    BusinessDataVO countByTime(LocalDateTime beginTime, LocalDateTime endTime);
}
